/**
 * @Author 韦建韩
 * @Date 2022/5/6
 */
package com.example.devops.Manage.threadManager;

import com.example.devops.Manage.ProcessInfoManage;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class ProjectPublishThread implements Runnable {
    Logger log = LoggerFactory.getLogger(ProjectPublishThread.class);
    private int userId;
    private String gitAddr;
    private String branch;

    public ProjectPublishThread(int userId, String gitAddr, String branch){
        this.userId = userId;
        this.gitAddr = gitAddr;
        this.branch = branch;
    }
    @SneakyThrows
    @Override
    public void run() {
        Process  p = Runtime.getRuntime().exec("/java/shell/projectPublish.sh" + " "+userId+" "+gitAddr+" "+branch);
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8));
        String line;
        StringBuffer infoObject = ProcessInfoManage.getInfoObject();
        while ((line = bufferedReader.readLine()) != null) {
            infoObject.append(line);
        }
        p.waitFor();

    }
}
